<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>范闲商城-忘记密码</title>
	<link rel="stylesheet" type="text/css" th:href="@{/static/css/reset.css}">
	<link rel="stylesheet" type="text/css" th:href="@{/static/css/main.css}">
	<link rel="stylesheet" th:href="@{/static/layui/css/layui.css}">
	<script th:src="@{/static/layui/layui.js}" type="text/javascript" charset="utf-8"></script>
	<script th:src="@{/static/jquery-2.1.4.js}" type="text/javascript" charset="utf-8"></script>
	<script th:src="@{/static/mylayer.js}" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript" th:src="@{js/register.js}"></script>
	<style>
		html, body {
			height: 100%;
			margin: 0;
		}

		body {
			display: flex;
			flex-direction: column;
			min-height: 100vh;
		}

		.content {
			flex: 1;
		}
		body {
			background: url(../static/pic/background.jpg) no-repeat center;
			background-size: cover;
		}
		.title-box{
			height: 40px;
			background: url(../static/pic/fxsc-forget.png) no-repeat center;
			background-size: 100%;
		}
		.logo img {
			position: absolute; /* 将图片设置为绝对定位 */
			left: 50px; /* 将图片向右偏移200px */
			top: 0; /* 将图片置于父元素的顶部 */
		}
		.demo-reg-container {
			width: 320px;
			margin: 21px auto 0;
			position: absolute;
			top: 40%;
			right: 20%;
			transform: translateY(-50%);
			background-color: rgba(255, 255, 255, 0.8);
			padding: 20px;
			border-radius: 10px;
			box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
		}
	</style>
</head>
<body>
	<style>
		.demo-reg-container{width: 320px; margin: 21px auto 0;}
		.demo-reg-other .layui-icon{position: relative; display: inline-block; margin: 0 2px; top: 2px; font-size: 26px;}
	</style>
	<div class="content">
		<form class="layui-form">
			<div class="demo-reg-container">
				<div class="title-box"></div><br>
				<div class="layui-form-item">
					<div class="layui-input-wrap">
						<div class="layui-input-prefix">
							<i class="layui-icon layui-icon-username"></i>
						</div>
						<input type="text" name="account" value="" lay-verify="required" placeholder="账号" autocomplete="off" class="layui-input" lay-affix="clear">
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-row">
						<div class="layui-col-xs7">
							<div class="layui-input-wrap">
								<div class="layui-input-prefix">
									<i class="layui-icon layui-icon-cellphone"></i>
								</div>
								<input type="text" name="phone" value="" lay-verify="required|phone" placeholder="手机号" lay-reqtext="请填写手机号" autocomplete="off" class="layui-input" id="reg-cellphone">
							</div>
						</div>
						<div class="layui-col-xs5">
							<div style="margin-left: 11px;">
								<button type="button" class="layui-btn layui-btn-fluid layui-btn-primary" lay-on="reg-get-vercode">获取验证码</button>
							</div>
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-wrap">
						<div class="layui-input-prefix">
							<i class="layui-icon layui-icon-vercode"></i>
						</div>
						<input type="text" name="vercode" value="" lay-verify="required" placeholder="验证码" lay-reqtext="请填写验证码" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-wrap">
						<div class="layui-input-prefix">
							<i class="layui-icon layui-icon-password"></i>
						</div>
						<input type="password" name="password" value="" lay-verify="required" placeholder="密码" autocomplete="off" class="layui-input" id="reg-password" lay-affix="eye">
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-wrap">
						<div class="layui-input-prefix">
							<i class="layui-icon layui-icon-password"></i>
						</div>
						<input type="password" name="confirmPassword" value="" lay-verify="required|confirmPassword" placeholder="确认密码" autocomplete="off" class="layui-input" lay-affix="eye">
					</div>
				</div>
				<div class="layui-form-item">
					<input type="checkbox" name="agreement" lay-verify="required" lay-skin="primary" title="同意">
					<a href="#terms" target="_blank" style="position: relative; top: 6px; left: -15px;">
						<ins>用户协议</ins>
					</a>
				</div>
				<div class="layui-form-item">
					<button class="layui-btn layui-btn-fluid" lay-submit lay-filter="forget">修改</button>
				</div>
				<div class="layui-form-item demo-reg-other">
					<label>社交账号登录</label>
					<span style="padding: 0 21px 0 6px;">
						<a href="javascript:;"><i class="layui-icon layui-icon-login-qq" style="color: #3492ed;"></i></a>
						<a href="javascript:;"><i class="layui-icon layui-icon-login-wechat" style="color: #4daf29;"></i></a>
						<a href="javascript:;"><i class="layui-icon layui-icon-login-weibo" style="color: #cf1900;"></i></a>
					</span>
					<em id="login"></em>
				</div>
			</div>
		</form>
	</div>

	<div class="footer no-mp">
		<div class="foot_link">
			<a href="#">关于我们</a>
			<span>|</span>
			<a href="#">联系我们</a>
			<span>|</span>
			<a href="#">招聘人才</a>
			<span>|</span>
			<a href="#">友情链接</a>		
		</div>
		<p>CopyRight © 2024 北京鑫鑫科技有限公司 All Rights Reserved</p>
		<p>电话：010-8888888    京ICP备88888888号</p>
	</div>
	<script>
		layui.use(function(){
			var $ = layui.$;
			var form = layui.form;
			var layer = layui.layer;
			var util = layui.util;

			var queryString = window.location.search;
			var urlParams = new URLSearchParams(queryString);
			var returnUri = urlParams.get("returnUri");
			console.log(returnUri);
			var categoryId = urlParams.get("categoryId");
			var parentId = urlParams.get("parentId");
			var productId = urlParams.get("productId");
			console.log(returnUri);
			if (returnUri == null || returnUri === "") {
				returnUris = '/';
			} else {
				returnUris = returnUri;
				if (parentId == null || parentId === "") {
					returnUris = returnUris;
				} else {
					returnUris = returnUris + '&' + 'parentId=' + parentId;
				}
				if (categoryId == null || categoryId === "") {
					returnUris = returnUris;
				} else {
					returnUris = returnUris + '&' + 'categoryId=' + categoryId;
				}
				if (productId == null || productId === "") {
					returnUris = returnUris;
				} else {
					returnUris = returnUris + '&' + 'productId=' + productId;
				}
			}

			$("#login").append('<a href="/page/login?returnUri='+returnUris+'">登录已有帐号</a>');

			// 自定义验证规则
			form.verify({
				// 确认密码
				confirmPassword: function(value, item){
					var passwordValue = $('#reg-password').val();
					if(value !== passwordValue){
						return '两次密码输入不一致';
					}
				}
			});

			// 提交事件
			form.on('submit(forget)', function(data){
				var field = data.field; // 获取表单字段值

				// 是否勾选同意
				if(!field.agreement){
					layer.msg('您必须勾选同意用户协议才能注册');
					return false;
				}

				// 显示填写结果，仅作演示用
				// layer.alert(JSON.stringify(field), {
				// 	title: '当前填写的字段值'
				// });

				$.post(
						'/user/forget',
						field,
						function (result) {
							if (result.code == 0) {
								mylayer.okUrl(result.msg, '/page/login?returnUri='+returnUris+'');
							} else {
								mylayer.errorMsg(result.msg);
							}
						},
						'json'
				);

				return false; // 阻止默认 form 跳转
			});

			// 普通事件
			util.on('lay-on', {
				// 获取验证码
				'reg-get-vercode': function(othis){
					var isvalid = form.validate('#reg-cellphone'); // 主动触发验证，v2.7.0 新增
					// 验证通过
					if(isvalid){
						//layer.msg('手机号规则验证通过');
						layer.msg('手机验证码为1234');
						// 此处可继续书写「发送验证码」等后续逻辑
						// …
					}
				}
			});
		});
	</script>
</body>
</html>